﻿using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using wt.wine.Application.Common.Interfaces;
using wt.wine.Application.Common.Models;

namespace wt.wine.Application.ManageDevicetable.Queries
{
    public class GetDeviceNameByAddWineIdQueries:IRequest<Json<GetDeviceNameByAddWineDTO>>
    {
        public int deviceId { get; set; }
    }

    public class GetDeviceNameByAddWineIdQueriesHandle : IRequestHandler<GetDeviceNameByAddWineIdQueries, Json<GetDeviceNameByAddWineDTO>>
    {
        private readonly ICurrentUserService _icurrentUserServices;
        private readonly IDevicetableRepository _idevicetableRepository;
        public GetDeviceNameByAddWineIdQueriesHandle(ICurrentUserService icurrentUserServices, IDevicetableRepository idevicetableRepository)
        {
            _icurrentUserServices = icurrentUserServices;
            _idevicetableRepository = idevicetableRepository;
        }

        public async Task<Json<GetDeviceNameByAddWineDTO>> Handle(GetDeviceNameByAddWineIdQueries request, CancellationToken cancellationToken)
        {
            GetDeviceNameByAddWineDTO res = new();
            int userid = _icurrentUserServices.GetUserId();
            if (userid <= 0)
            {
                return Json<GetDeviceNameByAddWineDTO>.Failed("请先登录", res);
            }
            else
            {
                res = _idevicetableRepository.GetDeviceListByAddWine(userid,request.deviceId, cancellationToken);
                return Json<GetDeviceNameByAddWineDTO>.Success("查询成功", res);
            }
        }
    }
}
